home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ecstr3.arc / STRNLEN.C < prev    next >
C/C++ Source or Header  |  1987-03-04  |  736b  |  39 lines

  1. /*  File   : strnlen.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 10 April 1984
  4.     Defines: strnlen()
  5.  
  6.     strnlen(src, len)
  7.     returns the number of characters up to the first NUL in src, or len,
  8.     whichever is smaller.  This is the same as strnend(src,len)-src.
  9.  
  10.     Beware: the VaxAsm version only works for 0 <= len < 65535.
  11. */
  12.  
  13. #include "strings.h"
  14.  
  15. #if    VaxAsm
  16.  
  17. int strnlen(src, len)
  18.     char *src;
  19.     int len;
  20.     {
  21.        asm("locc $0,8(ap),*4(ap)");
  22.        asm("subl3 4(ap),r1,r0");
  23.     }
  24.  
  25. #else  ~VaxAsm
  26.  
  27. int strnlen(s, n)
  28.     register char *s;
  29.     register int n;
  30.     {
  31.        register int L;
  32.  
  33.        for (L = 0; --n >= 0 && *s++; L++) ;
  34.        return L;
  35.     }
  36.  
  37. #endif VaxAsm
  38.  
  39.